package com.brook.app.android.filepickertest;

import android.Manifest;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import android.util.Log;
import android.view.View;

import com.brook.app.android.filepicker.FilePickerUtils;
import com.brook.app.android.filepicker.core.FilePickCallback;
import com.brook.app.android.permissionutil.PermissionUtil;

import java.io.File;
import java.util.Arrays;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

    }

    public void startPicker(View view) {
        PermissionUtil.with(this)
                .permission(Manifest.permission.WRITE_EXTERNAL_STORAGE)
                .request(new PermissionUtil.PermissionCallback() {
                    @Override
                    public void onGranted() {
                        try {
                            FilePickerUtils
                                    .createVideoConfig()
//                                    .createImageConfig()
                                    .setPickCount(3)
//                                    .setVideoMaxDuration(60)
                                    .setFileSize(50 * 1024)
                                    .build()
                                    .mergeDefaultConfig()
                                    .launchPicker(MainActivity.this, new FilePickCallback() {
                                        @Override
                                        public void onPickResult(List<File> file) {
                                            Log.d("TAG", "回调" + Arrays.toString(file.toArray()));
                                        }
                                    });
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }

                    @Override
                    public void onDenied(List<String> permissionList) {

                    }
                });
    }
}
